package ${model.packageName}.api.facade;

import org.springframework.stereotype.Service;

import ${model.packageName}.api.bean.request.${model.initUpperName}CreateRequest;
import ${model.packageName}.api.bean.request.${model.initUpperName}UpdateRequest;
import ${model.packageName}.api.bean.request.${model.initUpperName}DeleteRequest;
import ${model.packageName}.api.converter.${model.initUpperName}ApiConverter;
import ${model.packageName}.model.${model.initUpperName}Model;
import ${model.packageName}.service.${model.initUpperName}WriteService;

import io.terminus.common.model.Response;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ${model.initUpperName}WriteFacadeImpl implements ${model.initUpperName}WriteFacade {

	private final ${model.initUpperName}WriteService ${model.initLowerName}WriteService;	
	private final ${model.initUpperName}ApiConverter ${model.initLowerName}ApiConverter;
	
	@Override
	public Response<Boolean> create${model.initUpperName}(${model.initUpperName}CreateRequest request) {
		${model.initUpperName}Model model = ${model.initLowerName}ApiConverter.get(request);
		Boolean isSuccess = ${model.initLowerName}WriteService.create${model.initUpperName}(model);
		if(isSuccess) {
			return Response.ok(isSuccess);
		}
		else {
			return Response.fail("创建${model.desc}失败。");
		}		
	}

	@Override
	public Response<Boolean> update${model.initUpperName}(${model.initUpperName}UpdateRequest request) {
		${model.initUpperName}Model model = ${model.initLowerName}ApiConverter.get(request);
		Boolean isSuccess = ${model.initLowerName}WriteService.update${model.initUpperName}(model);
		if(isSuccess) {
			return Response.ok(isSuccess);
		}
		else {
			return Response.fail("修改${model.desc}失败。");
		}		
	}
	
	@Override
	public Response<Boolean> delete${model.initUpperName}(${model.initUpperName}DeleteRequest request) {
		${model.initUpperName}Model model = ${model.initLowerName}ApiConverter.get(request);
		Boolean isSuccess = ${model.initLowerName}WriteService.delete${model.initUpperName}(model);
		if(isSuccess) {
			return Response.ok(isSuccess);
		}
		else {
			return Response.fail("删除${model.desc}失败。");
		}		
	}

}
